package StudyCode.summary.myfile;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CombinesMultipleByteArrays {

	public static void main(String[] argv) {
		byte[] a = new byte[]{34, 35, 36, 37, 37};
		byte[] b = new byte[]{37, 67, 68, 69};
		System.out.println("byte 数组a:" + Arrays.toString(a));
		System.out.println("byte 数组b:" + Arrays.toString(a));
		System.out.println("byte 数组 a 跟 b合并后:" + Arrays.toString(combineArrays(a, b)));
	}

	private static byte[] combineArrays(byte[]... a) {
		int massLength = 0;
		for (byte[] b : a) {
			massLength += b.length;
		}
		byte[] c = new byte[massLength];
		byte[] d;
		int index = 0;
		for (byte[] anA : a) {
			d = anA;
			System.arraycopy(d, 0, c, 0 + index, d.length);
			index += d.length;
		}
		return c;
	}
}
